﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using PCMSofCC.BLL;

namespace PCMSofCC.GroupLeader
{
    public partial class ReviewRecordStep1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                GoogleMapForASPNet1.GoogleMapObject.APIKey = ConfigurationManager.AppSettings["GoogleAPIKey"];
                GoogleMapForASPNet1.GoogleMapObject.APIVersion = "2";
                GoogleMapForASPNet1.GoogleMapObject.Width = "590px";
                GoogleMapForASPNet1.GoogleMapObject.Height = "489px";
                GoogleMapForASPNet1.GoogleMapObject.ZoomLevel = 12;
                GoogleMapForASPNet1.GoogleMapObject.AutomaticBoundaryAndZoom = false;
                GooglePoint GP = new GooglePoint("1", 30.59, 114.30);
                GoogleMapForASPNet1.GoogleMapObject.CenterPoint = GP;
                GoogleMapForASPNet1.GoogleMapObject.Points.Add(GP);
            }

        }

        protected void SiteList_SelectedIndexChanged(object sender, EventArgs e)
        {
            Site site = Sites.GetSite(int.Parse(SiteList.SelectedValue));
            GooglePoint GP = GoogleMapForASPNet1.GoogleMapObject.Points["1"];
            GP.Latitude = site.Latitude;
            GP.Longitude = site.Longitude;
            MapRecenter(GoogleMapForASPNet1.GoogleMapObject.Points["1"]);
            btnSubmit.Enabled = true;
        }

        private void MapRecenter(GooglePoint point)
        {
            GoogleMapForASPNet1.GoogleMapObject.CenterPoint = point;
            GoogleMapForASPNet1.GoogleMapObject.RecenterMap = true;
        }

        protected void Calendar1_SelectionChanged(object sender, EventArgs e)
        {
            DateTime date = Calendar1.SelectedDate;
            SiteList.DataSource = Sites.GetAssignedSites(date);
            SiteList.DataTextField = "Name";
            SiteList.DataValueField = "Id";
            SiteList.DataBind();
            btnSubmit.Enabled = false;
        }
    }
}
